package com.example.androidhive;


import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity2 extends android.support.v4.app.FragmentActivity {	
	
	GoogleMap googleMap;
	double a; 
	double b;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.aa);
		
		SupportMapFragment supportMapFragment = (SupportMapFragment) 
							getSupportFragmentManager().findFragmentById(R.id.map);
		googleMap = supportMapFragment.getMap();
		googleMap.setOnMapClickListener(new OnMapClickListener() {
			@Override
			public void onMapClick(LatLng latLng) {
				MarkerOptions markerOptions = new MarkerOptions();
				markerOptions.position(latLng);
				markerOptions.title(latLng.latitude + " : " + latLng.longitude);
				googleMap.clear();
				googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
				googleMap.addMarker(markerOptions);
				a=latLng.latitude; 
				 b=latLng.longitude;
				TextView co = (TextView) findViewById(R.id.ma);
				co.setText(a+",,,"+b);
				
			}
		});
		Button e=(Button)findViewById(R.id.zapislokalizacji);
		e.setOnClickListener(new OnClickListener() {
			  @Override
			  public void onClick(View v) {
				  Map<String,String> mma=new HashMap<String,String>();
				  mma.put("nazwa", "mm");
				  mma.put("wsp_x",String.valueOf(a));
				  mma.put("wsp_y",String.valueOf(b));
				  				Base_ aa=new Base_(MainActivity2.this,mma,getApplicationContext());
				  				aa.setAaa(new String[]{"lokalizacja"});
		  				aa.execute();
		  				/*try{
		  					Thread.sleep(3000);
		  				}*/
		  				//catch(Exception e){}
		  				new File_().addToMap("haslo", "oo", 0);
			  }
			});
		 
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
	//	getMenuInflater().inflate(R.menu.gmaps, menu);
		return true;
	}
}